package com.itheima.blog.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.blog.admin.dto.OperationLogDto;
import com.itheima.blog.admin.entity.OperationLogTable;
import com.itheima.blog.admin.dao.OperationLogTableMapper;
import com.itheima.blog.admin.service.IOperationLogTableService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.common.domain.PageReqDto;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zwp
 * @since 2023-07-11
 */
@Service
public class OperationLogTableServiceImpl extends ServiceImpl<OperationLogTableMapper, OperationLogTable> implements IOperationLogTableService {

    @Override
    public IPage<OperationLogTable> getOpertion(PageReqDto page, OperationLogDto operationLogDto) {
        if (operationLogDto!=null){
            /*QueryWrapper<OperationLogTable> queryWrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(operationLogDto.getUserName())){
                queryWrapper.lambda().eq(OperationLogTable::getUserName,operationLogDto.getUserName());
            }
            if (StringUtils.isNotBlank(operationLogDto.getIp())){
                queryWrapper.lambda().eq(OperationLogTable::getIp,operationLogDto.getIp());
            }
            if (StringUtils.isNotBlank(operationLogDto.getInterfaceName())){
                queryWrapper.lambda().like(OperationLogTable::getInterfaceName,operationLogDto.getInterfaceName());
            }
            if (operationLogDto.getTimeConsuming()!=null){
                queryWrapper.lambda().le(OperationLogTable::getTimeConsuming,operationLogDto.getTimeConsuming());
            }
            if (operationLogDto.getStartTime()!=null && operationLogDto.getEndTime()!=null){
                queryWrapper.lambda().between(OperationLogTable::getCreationTime,operationLogDto.getStartTime(),operationLogDto.getEndTime());
            }*/
            lambdaQuery().eq(StringUtils.isNotBlank(operationLogDto.getUserName()),OperationLogTable::getUserName,operationLogDto.getUserName())
                    .eq(StringUtils.isNotBlank(operationLogDto.getIp()),OperationLogTable::getIp,operationLogDto.getIp())
                    .like(StringUtils.isNotBlank(operationLogDto.getInterfaceName()),OperationLogTable::getInterfaceName,operationLogDto.getInterfaceName())
                    .le(operationLogDto.getTimeConsuming()!=null,OperationLogTable::getTimeConsuming,operationLogDto.getTimeConsuming())
                    .between(operationLogDto.getStartTime()!=null && operationLogDto.getEndTime()!=null,OperationLogTable::getCreationTime,operationLogDto.getStartTime(),operationLogDto.getEndTime());
        }
        IPage<OperationLogTable> operationLogTableIPage = lambdaQuery().page(new Page<>(page.getPage(),page.getSize()));
        return operationLogTableIPage;
    }
}
